package com.mrx.pvzcommunity.controller;

import com.mrx.pvzcommunity.model.Result;
import com.mrx.pvzcommunity.model.user.NormalUser;
import com.mrx.pvzcommunity.model.user.User;
import com.mrx.pvzcommunity.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Api(tags = "关注操作")
@RequestMapping(value = "/friends")
@CrossOrigin(originPatterns = "*", allowCredentials = "true")

public class FriendController {
    private final UserService userService;

    @GetMapping("/{uid}")
    @ApiOperation(value = "关注查询", notes = "查指定 uid 的关注列表")
    @ApiImplicitParam(name = "uid", value = "用户 id", dataTypeClass = Integer.class, required = true, example = "1")

    public Result<List<NormalUser>> getFriendsByUid(@PathVariable String uid) {
        return userService.getFriendsByUid(uid);
    }

    @GetMapping("/follow/{uid}")
    @ApiOperation(value = "关注好友", notes = "关注指定 uid 的用户")
    @ApiImplicitParam(name = "uid", value = "用户 id", dataTypeClass = Integer.class, required = true, example = "1")

    public Result<String> followUserByUid(@PathVariable String uid, @ApiIgnore @SessionAttribute(value = "user", required = false) User user) {
        return userService.followUserByUid(user, uid);
    }

}
